#delimit;
*for REStat paper, "Breastfeeding and Children's Early Cognitive Outcomes."
log using d:/data/kprop.log, replace;
clear;
set mem 40m;
set more off;
set matsize 800;
set seed 12345;

use d:/data/kind2;

gen wkr0x = int(wkr0);
drop wkr0;

**summarize [fweight = wkr0x];

summarize;

*summarize if bfeed==0;
*summarize if bfeed==1;
*summarize if bf1==1;
*summarize if bf23==1;
*summarize if bf45==1;
*summarize if bf6p==1;


replace smoke = 0 if smokedv == 1;
replace csect = 0 if csectdv == 1;
replace r1ptest = 0 if r1ptestd == 1;
replace regne = 0 if regdv==1;
replace regs = 0 if regdv==1;
replace regw = 0 if regdv==1;
replace regnc = 0 if regdv==1;

replace gestlt35 = 0 if gestdv == 1;
replace gest3537 = 0 if gestdv == 1;
replace bwtvl = 0 if bwtdv == 1;
replace bwtlow = 0 if bwtdv == 1;
replace agebirth = 0 if agedv == 1;
replace pwork16 = 0 if pworkdv == 1;
replace pwork712 = 0 if pworkdv == 1;
replace wicp = 0 if wicpdv == 1;
replace bfathed = 0 if dadeddv == 1;

gen momed2 = momed*momed;
gen daded2 = bfathed*bfathed;
gen hmomed = hispanic*momed;

gen abwtvl = asian*bwtvl;
gen bbwtvl = black*bwtvl;
gen hbwtvl = hispanic*bwtvl;


**now, what if interact low birth weight with everything;
gen lfem = bwtlow*female;
gen lbla = bwtlow*black;
gen lhis = bwtlow*hispanic;
gen lasi = bwtlow*asian;
gen lchi = bwtlow*chinese;
gen lame = bwtlow*amerind;
gen ltwi = bwtlow*twin;
gen lama = bwtlow*marbirth; 
gen lage = bwtlow*agebirth ;
gen led = bwtlow*momed; 
gen lpre = bwtlow*prenat; 
gen lsmo = bwtlow*smoke; 
gen lw = bwtlow*regw; 
gen lfo = bwtlow*foreign; 
gen lcs = bwtlow*csect; 
gen lfa = bwtlow*bfathed; 
gen l16 = bwtlow*pwork16 ;
gen l12 = bwtlow*pwork712 ;

gen vlfo = bwtvl*foreign; 
gen vled = bwtvl*momed;
gen vlfa = bwtvl*bfathed; 

**now, what if interact region nc with everything;
gen ncfem = regnc*female;
gen ncbla = regnc*black;
gen nchis = regnc*hispanic;
gen ncasi = regnc*asian;
gen ncchi = regnc*chinese;
gen ncame = regnc*amerind;
gen nctwi = regnc*twin;
gen ncama = regnc*marbirth; 
gen ncage = regnc*agebirth ;
gen nced = regnc*momed; 
gen ncpre = regnc*prenat; 
gen ncsmo = regnc*smoke; 
gen ncfo = regnc*foreign; 
gen nccs = regnc*csect; 
gen ncfa = regnc*bfathed; 
gen nc16 = regnc*pwork16 ;
gen nc12 = regnc*pwork712 ;


**plain model;
psmatch2 bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke  regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv pworkdv
momed2 daded2 hmomed abwtvl hbwtvl bbwtvl lbla lhis lasi lfo led vlfo vled lfa ,
outcome(kmathtx) trim(3) logit kernel k(epan) bw(.05) common;

**bootstrap standard errors;
bs "psmatch2 bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke  regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv pworkdv
momed2 daded2 hmomed abwtvl hbwtvl bbwtvl lbla lhis lasi lfo led vlfo vled lfa,
outcome(kmathtx) trim(3) logit kernel k(epan) bw(.05) common" "r(att)", reps(500);

psmatch2 bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv pworkdv
momed2 daded2 hmomed abwtvl hbwtvl bbwtvl lbla lhis lasi lfo led vlfo vled  lfa ,
outcome(kreadtx) trim(3) logit kernel k(epan) bw(.05) common;

bs "psmatch2 bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke  regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv pworkdv
momed2 daded2 hmomed abwtvl hbwtvl bbwtvl lbla lhis lasi lfo led vlfo vled lfa,
outcome(kreadtx) trim(3) logit kernel k(epan) bw(.05) common" "r(att)", reps(500);

**regression based testing from Smith paper;
drop if _support==0;

gen pscore2 = _pscore*_pscore;
gen pscore3 = _pscore*_pscore*_pscore;
gen pscore4 = _pscore*_pscore*_pscore*_pscore;

gen bfp = bfeed*_pscore;
gen bfp2 = bfeed*_pscore*_pscore;
gen bfp3 = bfeed*_pscore*_pscore*_pscore;
gen bfp4 = bfeed*_pscore*_pscore*_pscore*_pscore;

reg female _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg black _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg hispanic _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg asian _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg chinese _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg amerind _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg twin _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg border1 _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg border2 _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg bwtvl _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg bwtlow _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg marbirth _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg agebirth _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg momed _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg prenat _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg smoke _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

**reg regnc _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg regs _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg regw _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg foreign _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg csect _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg gestlt35 _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg gest3537 _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg pwork16 _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg pwork712 _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg smokedv _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg csectdv _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg regdv _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg gestdv _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg bwtdv _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg pworkdv _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg wicp _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg wicpdv _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg bfathed _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg dadeddv _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

**additions;
reg momed2 _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg daded2 _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg hmomed _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg abwtvl _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg bbwtvl _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg hbwtvl _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

reg lbla _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;
reg lhis _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;
reg lasi _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;
reg led _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;
reg lfo _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;
reg vled _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;
reg vlfo _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;
reg lfa _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;

**reg nchis _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;
**reg ncasi _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;
**reg ncfo _pscore pscore2 pscore3 pscore4 bfeed bfp bfp2 bfp3 bfp4;
test bfeed bfp bfp2 bfp3 bfp4;



log close; 
